import { ipcMain } from 'electron'
import { exec } from './handleUtils'
import windowUtils from './windowUtils'



ipcMain.handle('exec-app',
     async (_event, args) => {
    const psArgs = JSON.parse(args)
    const { handle, debugList  } = await exec(psArgs.path)

    handle.on('close', () => {
        if (windowUtils.mainWindow) {
            console.log('app close')
            windowUtils.mainWindow.webContents.send('app-close', args)
        }
    })

    return debugList
})

ipcMain.handle('open-debug', (_event, devUrl: string) => {
    const window = windowUtils.createDebugWindow()

    window.loadURL(devUrl)
})